package com.github.jedis.template;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class JedisConnect {

    @Autowired
    private RedisTemplate redisTemplate;

    public boolean add() {
        Boolean rel = (Boolean) redisTemplate.execute(new RedisCallback<Boolean>() {
            @Override
            public Boolean doInRedis(RedisConnection redisConnection) throws DataAccessException {
                return redisConnection.setNX("abcd".getBytes(), "opq".getBytes());
            }
        });
        return rel;
    }
}
